package com.kili.mirco.spark_als.init;

import com.kili.mirco.spark_als.com.ModuleType;
import com.kili.mirco.spark_als.ref.factory.ModelFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;


/**
 * @date 19-6-3
 * @auther jackliang
 * @description TODO
 */
@Slf4j
public class InitClassConfig {


    public static Properties properties = null;

    static {
        try {
            properties = PropertiesLoaderUtils.loadAllProperties("application.properties");
        } catch (IOException e) {
            System.exit(-1);
        }
    }


    @PostConstruct
    private void init() {
        try {
            Enumeration enums = properties.propertyNames();
            do {
                String var = String.valueOf(enums.nextElement());
                ModelFactory.BEANS.put(var, Class.forName(properties.getProperty(var)));
            } while (enums.hasMoreElements());
        } catch (Exception e) {
            log.error("[init] Loader for properties is matched a  error", e);
            System.exit(-1);
        }

    }

    public static String getProperty(ModuleType var) {
        return properties.getProperty(var.name());
    }


}
